//
//  GJButton.m
//  YDGJ
//
//  Created by 黄卫 on 17/2/24.
//  Copyright © 2017年 huangwei. All rights reserved.
//


#import "GJButton.h"



@interface GJButton ()

@property (nonatomic, copy) void (^block)(NSInteger);

@end

@implementation GJButton

+ (instancetype)addButtonOnSuperview:(UIView *)supview withOrigion:(CGPoint)org width:(CGFloat)width title:(NSString *)str image:(UIImage *)img clickBlock:(void (^)(NSInteger))blk
{
    return [[self alloc] initWithOrigion:org width:width title:str image:img superview:supview clickBlock:blk];
}

- (instancetype)initWithOrigion:(CGPoint)org width:(CGFloat)width title:(NSString *)str image:(UIImage *)img superview:(UIView *)supview clickBlock:(void (^)(NSInteger))blk
{
    str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    GJButton *btn = [GJButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(org.x, org.y, width, GJ_btn_H);
    [btn setBackgroundImage:imageWithColor(GJ_Btn_NormalColor) forState:UIControlStateNormal];
    [btn setBackgroundImage:imageWithColor(GJ_Btn_HighlightedColor) forState:UIControlStateHighlighted];
    [btn setBackgroundImage:imageWithColor(GJ_Btn_DisabledColor) forState:UIControlStateDisabled];
    [btn setTitle:str forState:UIControlStateNormal];
    [btn setTitleColor:WhiteColor forState:UIControlStateNormal];
    [btn setTitleColor:UIColorFromRGB(0xa4a4a4) forState:UIControlStateDisabled];
    [btn.titleLabel setFont:FontCustomSize(16)];
    [btn setImage:img forState:UIControlStateNormal];
    [btn addTarget:btn action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    btn.block = blk;
    btn.layer.cornerRadius = 3;
    btn.layer.masksToBounds = YES;
    [supview addSubview:btn];
    return btn;
}

- (void)btnClicked:(id)sender
{
    if (_block) {
        _block(self.tag);
    }
}








@end
